home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
RpcalcLine
< prev
next >
Wrap
Text File
|
1995-06-28
|
1KB
|
31 lines
Rpcalc Line
Previous: <Rpcalc Input=>RpcalcInpu> * Next: <Rpcalc Expr=>RpcalcExpr> * Up: <Rpcalc Rules=>RpcalcRulf>
#Wrap on
{fH5}Explanation of {fCode}line{f}{f}
Now consider the definition of {fCode}line{f}:
#Wrap off
#fCode
line: '\\n'
| exp '\\n' \{ printf ("\\t%.10g\\n", $1); \}
;
#f
#Wrap on
The first alternative is a token which is a newline character; this means
that rpcalc accepts a blank line (and ignores it, since there is no
action). The second alternative is an expression followed by a newline.
This is the alternative that makes rpcalc useful. The semantic value of
the {fCode}exp{f} grouping is the value of {fCode}$1{f} because the {fCode}exp{f} in
question is the first symbol in the alternative. The action prints this
value, which is the result of the computation the user asked for.
This action is unusual because it does not assign a value to {fCode}$${f}. As
a consequence, the semantic value associated with the {fCode}line{f} is
uninitialized (its value will be unpredictable). This would be a bug if
that value were ever used, but we don't use it: once rpcalc has printed the
value of the user's input line, that value is no longer needed.